package net.hn.hnms.biz.mine.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.mine.service.BroadcastService;
import net.hn.hnms.biz.mine.vo.Broadcast;
import net.hn.hnms.biz.mine.vo.BroadcastDeviceVo;
import net.hn.hnms.sys.common.core.domain.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2023/3/1 16:26
 * 1.0 version
 */
@RestController
@RequestMapping("broadcast/emergency")
@Api(value = "广播控制器", tags = {"井下广播"})
@RequiredArgsConstructor
public class BroadcastController {
    private final BroadcastService broadcastService;
    @PostMapping("sendMes")
    @ApiOperation("发送广播")
    public R<String> sendMessage(@RequestBody @Validated Broadcast broadcast){
        try {
            byte[] data = broadcastService.getData(broadcast);
            String s = broadcastService.sendMsg(data);
            return R.ok(s);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return R.fail("消息内容编码异常");
        } catch (IOException e) {
            e.printStackTrace();
            return R.fail("消息播报异常");
        }

    }
    @GetMapping("getDevices")
    @ApiOperation("获取设备列表")
    public R<List<BroadcastDeviceVo>> getDevices(){
//        byte [] data ={0x4C,0x44,0x49,0x50,0x04,0x00,0x00,0x00,0x00,0x00,0x24,0x34};
//        try {
//            String s = broadcastService.sendMsg(data);
//            return R.ok(s);
//        } catch (IOException e) {
//            e.printStackTrace();
//            return R.ok(e.getMessage());
//        }
        List<BroadcastDeviceVo> list=new ArrayList<>();
        list.add(new BroadcastDeviceVo("11142406","101皮带机头"));
        list.add(new BroadcastDeviceVo("8193286","G3-1东胶机尾4联巷"));
        list.add(new BroadcastDeviceVo("8848646","G3-1108综采刮板机尾"));
        list.add(new BroadcastDeviceVo("8062214","G3-1108综采工作面刮板机头"));
        list.add(new BroadcastDeviceVo("8389894","G3-1109运输机头配电点"));
        list.add(new BroadcastDeviceVo("8324358","G3-1109运输顺槽迎头"));
        list.add(new BroadcastDeviceVo("11207942","G3-1202设备列车"));
        list.add(new BroadcastDeviceVo("10880262","G3-1204运输顺槽皮带机头"));
        list.add(new BroadcastDeviceVo("11011334","G3-1301辅运顺槽皮带机头"));
        list.add(new BroadcastDeviceVo("8455430","G3-1301运输顺槽迎头"));
        list.add(new BroadcastDeviceVo("8127760","G3-1煤一盘区避难硐室"));
        list.add(new BroadcastDeviceVo("8914182","G3-1煤电缆通道"));
        list.add(new BroadcastDeviceVo("8652038","G3-1煤西辅运"));
        list.add(new BroadcastDeviceVo("8783110","G3-1煤二盘区避难硐室"));
        list.add(new BroadcastDeviceVo("11076870","G3-1西部二部皮带检修通道"));
        return R.ok(list);
    }
}
